import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

class Login extends StatefulWidget {
  Login({Key key}) : super(key: key);

  @override
  _LoginState createState() => _LoginState();
}

class _LoginState extends State<Login> {
  String username, paddword;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
            // title: Text('首页'),
            automaticallyImplyLeading: false,
            backgroundColor: Colors.white,
            elevation: 0),
        body: Container(
            child: Padding(
          padding: EdgeInsets.all(20),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              SizedBox(
                height: 50,
              ),
              TextField(
                  decoration: InputDecoration(
                      hintText: 'username', border: OutlineInputBorder()),
                  onChanged: (val) {
                    this.setState(() {
                      this.username = val;
                    });
                  }),
              SizedBox(
                height: 10,
              ),
              TextField(
                  decoration: InputDecoration(
                    // icon: Icon(Icons.home),
                    hintText: 'password',
                    border: OutlineInputBorder(),
                  ),
                  obscureText: true,
                  onChanged: (val) {
                    this.setState(() {
                      this.paddword = val;
                    });
                  }),
              Container(
                
                  child: Row(
                children: <Widget>[
                  Expanded(
                      child: RaisedButton(
                    child: Text('点击登录'),
                    textColor: Colors.white,
                    color: Colors.blue,
                    elevation: 10,
                    onPressed: (){
                      this.andss(this.username, this.paddword);
                    },
                  )),
                ],
              ))
            ],
          ),
        )));
  }

  andss(String user, String pass) {
    bool tf;
    if (this.username != null &&
        this.username.length >= 5 &&
        this.paddword != null &&
        this.paddword.length >= 5) {
        if(user == 'admin'){
          Navigator.pushNamed(context, '/');
        } else {
          showDialog(
          context: context,
          child: AlertDialog(content: Text("账号或密码错误", style: TextStyle())));
        }
         
    } else {
      showDialog(
          context: context,
          child: AlertDialog(content: Text("请输入账号密码,测试账号 admin  密码自定义六个字母", style: TextStyle())));
    }
  }
}
